cmake_minimum_required(VERSION 3.0)
add_library(mathlib mymath.cxx mymath.h)
SET(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}/install) #设置默认安装路径

#如何安装头文件
target_include_directories(mathlib PUBLIC  
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>  #头文件源目录
    $<INSTALL_INTERFACE:include>) #头文件安装目录

#头文件名称    
set_target_properties(mathlib PROPERTIES PUBLIC_HEADER "mymath.h")    

#安装库文件
install(TARGETS mathlib
    EXPORT mathlib-targets
    PUBLIC_HEADER DESTINATION include/mathlib
    ARCHIVE DESTINATION lib
    LIBRARY DESTINATION lib
    RUNTIME DESTINATION bin)

#安装 cmake 文件    
install(EXPORT mathlib-targets
    FILE mathlib-config.cmake
    DESTINATION lib/cmake/mathlib)